package com.ss.android.newmedia.message.dialog;

import android.content.Context;
import android.support.v4.view.MotionEventCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.bytedance.common.utility.Logger;

public class ScrollLayout extends FrameLayout {
    private int a;
    private a b;
    private int c;
    private VelocityTracker d;
    private int e;
    private int f;
    private float g;
    private float h;
    private float i;
    private float j;
    private int k;
    private int l;
    private boolean m;
    private float n;
    private float o;

    public ScrollLayout(Context arg4) {
        super(arg4);
        this.a = 0;
        this.k = -1;
        this.m = false;
        this.n = 0f;
        this.o = 0f;
        this.a();
    }

    public ScrollLayout(Context arg4, AttributeSet arg5) {
        super(arg4, arg5);
        this.a = 0;
        this.k = -1;
        this.m = false;
        this.n = 0f;
        this.o = 0f;
        this.a();
    }

    public ScrollLayout(Context arg4, AttributeSet arg5, int arg6) {
        super(arg4, arg5, arg6);
        this.a = 0;
        this.k = -1;
        this.m = false;
        this.n = 0f;
        this.o = 0f;
        this.a();
    }

    private void a() {
        ViewConfiguration v0 = ViewConfiguration.get(this.getContext());
        this.c = v0.getScaledTouchSlop();
        this.e = v0.getScaledMinimumFlingVelocity();
        this.f = v0.getScaledMaximumFlingVelocity();
        this.l = ((int) (this.getContext().getResources().getDisplayMetrics().density * 25f));
    }

    private int a(MotionEvent arg3, int arg4) {
        int v1 = -1;
        int v0 = MotionEventCompat.findPointerIndex(arg3, arg4);
        if (v0 == v1) {
            this.k = v1;
        }

        return v0;
    }

    private void a(MotionEvent arg7) {
        int v2 = -1;
        int v0 = this.k;
        int v1 = this.a(arg7, v0);
        if (v0 != v2 && v1 != v2) {
            float v0_1 = arg7.getRawX();
            float v1_1 = Math.abs(v0_1 - this.j);
            float v2_1 = arg7.getRawY();
            float v3 = Math.abs(v2_1 - this.i);
            if (v1_1 > (((float) this.c)) && v1_1 > v3) {
                this.m = true;
                this.g = v0_1;
                this.h = v2_1;
                this.a = 0;
                return;
            }

            if (v3 <= (((float) this.c))) {
                return;
            }

            if (v3 <= v1_1) {
                return;
            }

            this.m = true;
            this.g = v0_1;
            this.h = v2_1;
            this.a = 1;
        }
    }

    private void b() {
        this.m = false;
        this.k = -1;
        if (this.d != null) {
            this.d.recycle();
            this.d = null;
        }
    }

    public boolean onInterceptTouchEvent(MotionEvent arg6) {
        boolean v0 = true;
        int v4 = -1;
        int v2 = arg6.getAction();
        if (v2 == 3 || v2 == 1) {
            this.b();
            v0 = false;
        } else {
            switch (v2 & 255) {
                case 0: {
                    this.k = arg6.getPointerId(arg6.getActionIndex());
                    if (this.k != v4) {
                        float v2_1 = arg6.getRawX();
                        this.g = v2_1;
                        this.j = v2_1;
                        v2_1 = arg6.getRawY();
                        this.h = v2_1;
                        this.i = v2_1;
                        this.m = false;
                    } else {
                    }

                    break;
                }
                case 2: {
                    if (this.k != v4) {
                        this.a(arg6);
                    } else {
                    }

                    break;
                }
            }

            if (!this.m) {
                if (this.d == null) {
                    this.d = VelocityTracker.obtain();
                }

                this.d.addMovement(arg6);
            }

            if (this.m) {
                return v0;
            }

            v0 = false;
        }

        return v0;
    }

    public boolean onTouchEvent(MotionEvent arg11) {
        float v0_2;
        int v1;
        int v0_1;
        int v5 = -1;
        if (this.d == null) {
            this.d = VelocityTracker.obtain();
        }

        this.d.addMovement(arg11);
        switch (arg11.getAction() & 255) {
            case 0: {
                this.k = arg11.getPointerId(arg11.getActionIndex());
                v0_2 = arg11.getRawY();
                this.i = v0_2;
                this.h = v0_2;
                v0_2 = arg11.getRawX();
                this.j = v0_2;
                this.g = v0_2;
                break;
            }
            case 2: {
                if (!this.m) {
                    this.a(arg11);
                }

                if (!this.m) {
                    return true;
                }

                this.a(arg11, this.k);
                if (this.k == v5) {
                    return true;
                }

                if (this.a == 1) {
                    v0_2 = arg11.getRawY();
                    float v3 = this.h - v0_2;
                    this.h = v0_2;
                    this.n += v3;
                    if (this.b == null) {
                        return true;
                    }

                    this.b.a(this.a, 0f, v3, 0f, this.n);
                    return true;
                }

                v0_2 = arg11.getRawX();
                float v5_1 = this.g - v0_2;
                this.g = v0_2;
                this.o += v5_1;
                if (this.b == null) {
                    return true;
                }

                this.b.a(this.a, v5_1, 0f, this.o, 0f);
                break;
            }
            case 1:
            case 3: {
                if (!this.m) {
                    return true;
                }

                VelocityTracker v0 = this.d;
                v0.computeCurrentVelocity(1000, ((float) this.f));
                if (this.a == 1) {
                    v0_1 = ((int) v0.getYVelocity(this.k));
                    this.a(arg11, this.k);
                    if (this.k != v5) {
                        v1 = ((int) (arg11.getRawY() - this.i));
                        if (Math.abs(v1) > this.l && Math.abs(v0_1) > this.e) {
                            if (v0_1 > 0 && v1 > 0) {
                                if (this.b != null) {
                                    this.b.a(this.a, false);
                                } else {
                                }

                            } else if (v0_1 < 0 && v1 < 0) {
                                if (this.b != null) {
                                    this.b.a(this.a, true);
                                } else {
                                }

                            } else if (this.b == null) {
                            } else {
                                this.b.a(this.a, 0f, this.n);
                            }
                        } else if (this.b == null) {
                        } else {
                            this.b.a(this.a, 0f, this.n);
                        }
                    }
                } else {
                    v0_1 = ((int) v0.getXVelocity(this.k));
                    this.a(arg11, this.k);
                    if (this.k == v5) {
                    } else {
                        v1 = ((int) (arg11.getRawX() - this.j));
                        if (Math.abs(v1) > this.l && Math.abs(v0_1) > this.e) {
                            if (v0_1 > 0 && v1 > 0) {
                                if (this.b != null) {
                                    this.b.a(this.a, false);
                                } else {
                                }
                            } else if (v0_1 < 0 && v1 < 0) {
                                if (this.b != null) {
                                    this.b.a(this.a, true);
                                } else {
                                }

                            } else if (this.b == null) {
                            } else {
                                this.b.a(this.a, this.o, 0f);
                            }
                        } else if (this.b == null) {
                        } else {
                            this.b.a(this.a, this.o, 0f);
                        }
                    }
                }

                label_99:
                this.o = 0f;
                this.n = 0f;
                this.k = v5;
                this.b();
                break;
            }
            case 5: {
                v0_1 = arg11.getActionIndex();
                this.h = arg11.getRawY();
                this.g = arg11.getRawX();
                this.k = MotionEventCompat.getPointerId(arg11, v0_1);
                break;
            }
            case 6: {
                this.a(arg11, this.k);
                if (this.k == v5) {
                    return true;
                }

                this.h = arg11.getRawY();
                this.g = arg11.getRawX();
                break;
            }
        }

        return true;
    }

    public void setCanTouch(boolean arg1) {
    }

    public void setOnScrollListener(a arg1) {
        this.b = arg1;
    }

    public static final class a {
        private final com.ss.android.newmedia.message.dialog.a a;

        a(com.ss.android.newmedia.message.dialog.a arg1) {
            this.a = arg1;

        }

        public final void a(int arg6, boolean arg7) {
            boolean v0 = true;
            if (Logger.debug()) {
                Logger.d("FloatDialog", "onFling() called with: scrollOrientation = [" + arg6 + "], isFlingLeftOrUp = [" + arg7 + "]");
            }

            if ((com.ss.android.newmedia.message.dialog.a.a(this.a) == null || !com.ss.android.newmedia.message.dialog.a.a(this.a).isRunning()) && (com.ss.android.newmedia.message.dialog.a.b(this.a) == null || !com.ss.android.newmedia.message.dialog.a.b(this.a).isRunning())) {
                if (arg6 != 0) {
                    if (!com.ss.android.newmedia.message.dialog.a.f(this.a)) {
                    } else if (arg7) {
                        com.ss.android.newmedia.message.dialog.a.k(this.a);
                    } else {
                        com.ss.android.newmedia.message.dialog.a.a(this.a, false, true);
                    }
                } else if (com.ss.android.newmedia.message.dialog.a.c(this.a)) {
                    com.ss.android.newmedia.message.dialog.a v2 = this.a;
                    if (arg7) {
                        v0 = false;
                    }

                    com.ss.android.newmedia.message.dialog.a.b(v2, v0);
                }

                com.ss.android.newmedia.message.dialog.a.a(this.a, false);
                if (!com.ss.android.newmedia.message.dialog.a.l(this.a)) {
                    return;
                }

                com.ss.android.newmedia.message.dialog.a.n(this.a).postDelayed(com.ss.android.newmedia.message.dialog.a.m(this.a), 200);
            }
        }

        public final void a(int arg6, float arg7, float arg8) {
            boolean v0 = true;
            if (Logger.debug()) {
                Logger.d("FloatDialog", "onScrollOver() called with: scrollOrientation = [" + arg6 + "], scrollX = [" + arg7 + "], scrollY = [" + arg8 + "]");
            }

            if ((com.ss.android.newmedia.message.dialog.a.a(this.a) == null || !com.ss.android.newmedia.message.dialog.a.a(this.a).isRunning()) && (com.ss.android.newmedia.message.dialog.a.b(this.a) == null || !com.ss.android.newmedia.message.dialog.a.b(this.a).isRunning())) {
                if (arg6 != 0) {
                    if (!com.ss.android.newmedia.message.dialog.a.f(this.a)) {
                    } else if (arg8 < (((float) (-com.ss.android.newmedia.message.dialog.a.o(this.a).d)))) {
                        com.ss.android.newmedia.message.dialog.a.a(this.a, false, true);
                    } else {
                        com.ss.android.newmedia.message.dialog.a.k(this.a);
                    }
                } else if (com.ss.android.newmedia.message.dialog.a.c(this.a)) {
                    if (Math.abs(arg7) > (((float) com.ss.android.newmedia.message.dialog.a.o(this.a).c))) {
                        com.ss.android.newmedia.message.dialog.a v2 = this.a;
                        if (arg7 >= 0f) {
                            v0 = false;
                        }

                        com.ss.android.newmedia.message.dialog.a.b(v2, v0);
                    } else {
                        com.ss.android.newmedia.message.dialog.a.p(this.a);
                    }
                }

                com.ss.android.newmedia.message.dialog.a.a(this.a, false);
                if (!com.ss.android.newmedia.message.dialog.a.l(this.a)) {
                    return;
                }

                com.ss.android.newmedia.message.dialog.a.n(this.a).postDelayed(com.ss.android.newmedia.message.dialog.a.m(this.a), 200);
            }
        }

        public final void a(int arg4, float arg5, float arg6, float arg7, float arg8) {
            if (Logger.debug()) {
                Logger.d("FloatDialog", "onScroll() called with: scrollOrientation = [" + arg4 + "], distanceX = [" + arg5 + "], distanceY = [" + arg6 + "], scrollX = [" + arg7 + "], scrollY = [" + arg8 + "]");
            }

            if ((com.ss.android.newmedia.message.dialog.a.a(this.a) == null || !com.ss.android.newmedia.message.dialog.a.a(this.a).isRunning()) && (com.ss.android.newmedia.message.dialog.a.b(this.a) == null || !com.ss.android.newmedia.message.dialog.a.b(this.a).isRunning())) {
                com.ss.android.newmedia.message.dialog.a.a(this.a, -(((int) arg7)));
                if (arg4 == 0) {
                    if (com.ss.android.newmedia.message.dialog.a.c(this.a)) {
                        com.ss.android.newmedia.message.dialog.a.e(this.a).setTranslationX(((float) com.ss.android.newmedia.message.dialog.a.d(this.a)));
                        com.ss.android.newmedia.message.dialog.a.b(this.a, com.ss.android.newmedia.message.dialog.a.d(this.a));
                    }
                } else if (com.ss.android.newmedia.message.dialog.a.f(this.a)) {
                    WindowManager.LayoutParams v0 = com.ss.android.newmedia.message.dialog.a.g(this.a);
                    v0.y = ((int) ((((float) v0.y)) + arg6));
                    if (com.ss.android.newmedia.message.dialog.a.g(this.a).y < com.ss.android.newmedia.message.dialog.a.h(this.a)) {
                        com.ss.android.newmedia.message.dialog.a.g(this.a).y = com.ss.android.newmedia.message.dialog.a.h(this.a);
                    }

                    if (com.ss.android.newmedia.message.dialog.a.g(this.a).y > com.ss.android.newmedia.message.dialog.a.i(this.a)) {
                        com.ss.android.newmedia.message.dialog.a.g(this.a).y = com.ss.android.newmedia.message.dialog.a.i(this.a);
                    }

                    com.ss.android.newmedia.message.dialog.a.b(this.a, com.ss.android.newmedia.message.dialog.a.i(this.a) - com.ss.android.newmedia.message.dialog.a.g(this.a).y);
                    com.ss.android.newmedia.message.dialog.a.j(this.a);
                }

                com.ss.android.newmedia.message.dialog.a.a(this.a, true);
            }
        }
    }
}

